<template>
  <div class="action-btn-control">
    <div class="item" v-for="item in value" :key="item.key">
      <div class="text">{{ item.alias || item.label }}</div>
      <a-switch
        v-model:checked="item.visible"
        :disabled="item.configDisabled"
      />
      <a-popover
        placement="topRight"
        trigger="click"
        overlayClassName="action-btn-control-popover"
        :getPopupContainer="GetPopupContainer"
      >
        <template #title>
          <p class="head">{{ item.desc }}</p>
        </template>
        <template #content>
          <div class="content">
            <p class="title">重命名</p>
            <div class="box">
              <a-input v-model:value="item.alias" :placeholder="item.label" />
              <a-button class="reback" @click="onReback(item)">
                恢复默认
              </a-button>
            </div>
          </div>
        </template>
        <rb-icon-button class="btn" type="icon-luoshu-form22" />
      </a-popover>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, reactive, toRefs } from 'vue';
import { GetPopupContainer } from '@/global/util/preUtils';

export default defineComponent({
  name: 'ActionBtnControl',
  props: {
    value: {
      type: Object,
      default: () => ({}),
    },
    controls: {
      type: Object,
      default: () => ({}),
    },
    controlKey: {
      type: String,
      default: () => '',
    },
    card: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props, context) {
    const val = computed({
      get: () => props.value,
      set: (val) =>
        context.emit('updateValue', val, props.controlKey, props.controls),
    });
    const onReback = (item: { [key: string]: any }) => {
      item.alias = '';
    };

    return {
      val,
      GetPopupContainer,
      onReback,
    };
  },
});
</script>

<style lang="less" scoped>
.action-btn-control {
  .item {
    .flexRow();
    line-height: 36px;
    border-bottom: 1px solid @rb-border-color-base;
    &:last-child {
      border-bottom: none;
    }
    .text {
      flex: 1;
    }
    .btn {
      margin-left: 24px;
      font-size: 20px;
    }
    :deep .action-btn-control-popover {
      width: 284px;
    }
    .head {
      padding: 4px 0;
      line-height: 24px;
      color: @rb-label-color;
      word-break: break-all;
    }
    .content {
      .title {
        font-weight: bold;
        margin-bottom: 8px;
      }
      .box {
        .flexRow();
        .reback {
          margin-left: 12px;
        }
      }
    }
  }
}
</style>
